import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart' as intl;

import 'app_localizations_en.dart';
import 'app_localizations_zh.dart';

// ignore_for_file: type=lint

/// Callers can lookup localized strings with an instance of AppLocalizations
/// returned by `AppLocalizations.of(context)`.
///
/// Applications need to include `AppLocalizations.delegate()` in their app's
/// `localizationDelegates` list, and the locales they support in the app's
/// `supportedLocales` list. For example:
///
/// ```dart
/// import 'l10n/app_localizations.dart';
///
/// return MaterialApp(
///   localizationsDelegates: AppLocalizations.localizationsDelegates,
///   supportedLocales: AppLocalizations.supportedLocales,
///   home: MyApplicationHome(),
/// );
/// ```
///
/// ## Update pubspec.yaml
///
/// Please make sure to update your pubspec.yaml to include the following
/// packages:
///
/// ```yaml
/// dependencies:
///   # Internationalization support.
///   flutter_localizations:
///     sdk: flutter
///   intl: any # Use the pinned version from flutter_localizations
///
///   # Rest of dependencies
/// ```
///
/// ## iOS Applications
///
/// iOS applications define key application metadata, including supported
/// locales, in an Info.plist file that is built into the application bundle.
/// To configure the locales supported by your app, you’ll need to edit this
/// file.
///
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.
/// Then, in the Project Navigator, open the Info.plist file under the Runner
/// project’s Runner folder.
///
/// Next, select the Information Property List item, select Add Item from the
/// Editor menu, then select Localizations from the pop-up menu.
///
/// Select and expand the newly-created Localizations item then, for each
/// locale your application supports, add a new item and select the locale
/// you wish to add from the pop-up menu in the Value field. This list should
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
/// property.
abstract class AppLocalizations {
  AppLocalizations(String locale)
      : localeName = intl.Intl.canonicalizedLocale(locale.toString());

  final String localeName;

  static AppLocalizations? of(BuildContext context) {
    return Localizations.of<AppLocalizations>(context, AppLocalizations);
  }

  static const LocalizationsDelegate<AppLocalizations> delegate =
      _AppLocalizationsDelegate();

  /// A list of this localizations delegate along with the default localizations
  /// delegates.
  ///
  /// Returns a list of localizations delegates containing this delegate along with
  /// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
  /// and GlobalWidgetsLocalizations.delegate.
  ///
  /// Additional delegates can be added by appending to this list in
  /// MaterialApp. This list does not have to be used at all if a custom list
  /// of delegates is preferred or required.
  static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
      <LocalizationsDelegate<dynamic>>[
    delegate,
    GlobalMaterialLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
  ];

  /// A list of this localizations delegate's supported locales.
  static const List<Locale> supportedLocales = <Locale>[
    Locale('en'),
    Locale('zh')
  ];

  /// 应用标题
  ///
  /// In zh, this message translates to:
  /// **'InNetBM'**
  String get appTitle;

  /// 首页菜单
  ///
  /// In zh, this message translates to:
  /// **'首页'**
  String get home;

  /// 设置菜单
  ///
  /// In zh, this message translates to:
  /// **'设置'**
  String get settings;

  /// 我的套餐菜单
  ///
  /// In zh, this message translates to:
  /// **'我的套餐'**
  String get myPlan;

  /// 服务列表标题
  ///
  /// In zh, this message translates to:
  /// **'服务列表'**
  String get serviceList;

  /// 端口标签
  ///
  /// In zh, this message translates to:
  /// **'端口'**
  String get port;

  /// 内网穿透链接标题
  ///
  /// In zh, this message translates to:
  /// **'内网穿透链接'**
  String get tunnelLink;

  /// 复制按钮
  ///
  /// In zh, this message translates to:
  /// **'复制'**
  String get copy;

  /// 打开按钮
  ///
  /// In zh, this message translates to:
  /// **'打开'**
  String get open;

  /// 开发者按钮
  ///
  /// In zh, this message translates to:
  /// **'开发者'**
  String get developer;

  /// 免费版按钮
  ///
  /// In zh, this message translates to:
  /// **'免费版'**
  String get freeVersion;

  /// 普通会员标签
  ///
  /// In zh, this message translates to:
  /// **'普通会员'**
  String get regularMember;

  /// 高级会员标签
  ///
  /// In zh, this message translates to:
  /// **'高级会员'**
  String get premiumMember;

  /// VIP会员标签
  ///
  /// In zh, this message translates to:
  /// **'VIP会员'**
  String get vipMember;

  /// 升级提示标题
  ///
  /// In zh, this message translates to:
  /// **'需要升级'**
  String get upgradeRequired;

  /// 升级提示消息
  ///
  /// In zh, this message translates to:
  /// **'您已达到当前会员等级的服务开启上限。\n\n普通会员：最多开启3个服务\n高级会员：最多开启10个服务\n\n请升级会员以开启更多服务。'**
  String get upgradeMessage;

  /// 升级按钮
  ///
  /// In zh, this message translates to:
  /// **'升级'**
  String get upgrade;

  /// 取消按钮
  ///
  /// In zh, this message translates to:
  /// **'取消'**
  String get cancel;

  /// 主题设置
  ///
  /// In zh, this message translates to:
  /// **'主题'**
  String get theme;

  /// 深色模式选项
  ///
  /// In zh, this message translates to:
  /// **'深色模式'**
  String get darkMode;

  /// 浅色模式选项
  ///
  /// In zh, this message translates to:
  /// **'浅色模式'**
  String get lightMode;

  /// 语言设置
  ///
  /// In zh, this message translates to:
  /// **'语言'**
  String get language;

  /// 软件更新
  ///
  /// In zh, this message translates to:
  /// **'软件更新'**
  String get softwareUpdate;

  /// 检查更新按钮
  ///
  /// In zh, this message translates to:
  /// **'检查更新'**
  String get checkForUpdates;

  /// 中文选项
  ///
  /// In zh, this message translates to:
  /// **'中文'**
  String get chinese;

  /// 英文选项
  ///
  /// In zh, this message translates to:
  /// **'English'**
  String get english;

  /// 当前版本标签
  ///
  /// In zh, this message translates to:
  /// **'当前版本'**
  String get currentVersion;

  /// 检查更新按钮
  ///
  /// In zh, this message translates to:
  /// **'检查更新'**
  String get checkUpdate;

  /// 最新版本提示
  ///
  /// In zh, this message translates to:
  /// **'当前已是最新版本'**
  String get currentLatestVersion;

  /// 确定按钮
  ///
  /// In zh, this message translates to:
  /// **'确定'**
  String get confirm;

  /// 服务列表刷新成功提示
  ///
  /// In zh, this message translates to:
  /// **'服务列表已刷新'**
  String get serviceListRefreshed;

  /// 刷新失败提示
  ///
  /// In zh, this message translates to:
  /// **'刷新失败'**
  String get refreshFailed;

  /// 服务状态更新失败提示
  ///
  /// In zh, this message translates to:
  /// **'服务状态更新失败'**
  String get serviceStatusUpdateFailed;

  /// 服务状态更新错误提示
  ///
  /// In zh, this message translates to:
  /// **'更新服务状态时出错'**
  String get serviceStatusUpdateError;

  /// 我的套餐页面标题
  ///
  /// In zh, this message translates to:
  /// **'我的套餐页面'**
  String get myPlanPage;

  /// 最大服务数量
  ///
  /// In zh, this message translates to:
  /// **'最多{count}个服务'**
  String maxServices(int count);

  /// 域名标签
  ///
  /// In zh, this message translates to:
  /// **'域名'**
  String get domain;

  /// 协议标签
  ///
  /// In zh, this message translates to:
  /// **'协议'**
  String get protocol;

  /// 未连接状态
  ///
  /// In zh, this message translates to:
  /// **'未连接'**
  String get disconnected;

  /// 连接中状态
  ///
  /// In zh, this message translates to:
  /// **'连接中...'**
  String get connecting;

  /// 已连接状态
  ///
  /// In zh, this message translates to:
  /// **'已连接'**
  String get connected;

  /// 连接失败状态
  ///
  /// In zh, this message translates to:
  /// **'连接失败'**
  String get connectionFailed;

  /// 待实现提示
  ///
  /// In zh, this message translates to:
  /// **'真实连接逻辑待实现'**
  String get realConnectionLogicTodo;

  /// 无服务时的提示
  ///
  /// In zh, this message translates to:
  /// **'暂无服务'**
  String get noServices;

  /// 加载状态提示
  ///
  /// In zh, this message translates to:
  /// **'加载中...'**
  String get loading;

  /// 服务数量限制提示
  ///
  /// In zh, this message translates to:
  /// **'您已达到当前会员等级的服务开启上限'**
  String get serviceLimitReached;

  /// 升级提示消息
  ///
  /// In zh, this message translates to:
  /// **'请升级会员以开启更多服务'**
  String get upgradeToEnableMore;

  /// 立即升级按钮文本
  ///
  /// In zh, this message translates to:
  /// **'立即升级'**
  String get upgradeNow;

  /// 服务更新失败提示
  ///
  /// In zh, this message translates to:
  /// **'服务更新失败'**
  String get serviceUpdateFailed;

  /// 服务更新错误信息
  ///
  /// In zh, this message translates to:
  /// **'服务更新错误：{error}'**
  String serviceUpdateError(String error);

  /// 密码输入提示
  ///
  /// In zh, this message translates to:
  /// **'请输入密码'**
  String get enterPassword;

  /// 密码错误提示
  ///
  /// In zh, this message translates to:
  /// **'密码错误'**
  String get passwordIncorrect;

  /// 代理设置标题
  ///
  /// In zh, this message translates to:
  /// **'代理设置'**
  String get proxySettings;

  /// 代理主机标签
  ///
  /// In zh, this message translates to:
  /// **'代理主机'**
  String get proxyHost;

  /// 代理端口标签
  ///
  /// In zh, this message translates to:
  /// **'代理端口'**
  String get proxyPort;

  /// 保存按钮
  ///
  /// In zh, this message translates to:
  /// **'保存'**
  String get save;

  /// 代理设置保存成功提示
  ///
  /// In zh, this message translates to:
  /// **'代理设置已保存'**
  String get proxySettingsSaved;

  /// 代理主机输入提示
  ///
  /// In zh, this message translates to:
  /// **'请输入代理服务器地址'**
  String get proxyHostHint;

  /// 代理端口输入提示
  ///
  /// In zh, this message translates to:
  /// **'请输入端口号'**
  String get proxyPortHint;

  /// 保存设置按钮
  ///
  /// In zh, this message translates to:
  /// **'保存设置'**
  String get saveSettings;

  /// 添加服务器按钮
  ///
  /// In zh, this message translates to:
  /// **'添加服务器'**
  String get addServer;

  /// IP地址标签
  ///
  /// In zh, this message translates to:
  /// **'IP地址'**
  String get ipAddress;

  /// IP地址输入提示
  ///
  /// In zh, this message translates to:
  /// **'请输入IP地址'**
  String get ipAddressHint;

  /// 端口号输入提示
  ///
  /// In zh, this message translates to:
  /// **'请输入端口号'**
  String get portHint;

  /// 添加按钮
  ///
  /// In zh, this message translates to:
  /// **'添加'**
  String get add;

  /// 退出按钮
  ///
  /// In zh, this message translates to:
  /// **'退出'**
  String get logout;

  /// 退出确认对话框标题
  ///
  /// In zh, this message translates to:
  /// **'确认退出'**
  String get logoutConfirmTitle;

  /// 退出确认对话框消息
  ///
  /// In zh, this message translates to:
  /// **'确定要退出登录吗？'**
  String get logoutConfirmMessage;
}

class _AppLocalizationsDelegate
    extends LocalizationsDelegate<AppLocalizations> {
  const _AppLocalizationsDelegate();

  @override
  Future<AppLocalizations> load(Locale locale) {
    return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
  }

  @override
  bool isSupported(Locale locale) =>
      <String>['en', 'zh'].contains(locale.languageCode);

  @override
  bool shouldReload(_AppLocalizationsDelegate old) => false;
}

AppLocalizations lookupAppLocalizations(Locale locale) {
  // Lookup logic when only language code is specified.
  switch (locale.languageCode) {
    case 'en':
      return AppLocalizationsEn();
    case 'zh':
      return AppLocalizationsZh();
  }

  throw FlutterError(
      'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
      'an issue with the localizations generation tool. Please file an issue '
      'on GitHub with a reproducible sample app and the gen-l10n configuration '
      'that was used.');
}
